from sqlmodel import Field, Relationship, SQLModel,text
import sqlalchemy as sa
from .base import SQLModelBase
from .resBase import BaseResponse
from typing import ForwardRef
class areaBase(SQLModel):
    regionCode: str = Field(max_length=20, title="区域代码", sa_column_kwargs={"comment": "区域代码","name":"region_code"})
    regionName: str = Field(max_length=20, title="区域名称", sa_column_kwargs={"comment": "区域名称","name":"region_name"})
    parentCode: str | None = Field(max_length=20, title="父级代码", sa_column_kwargs={"comment": "父级代码","name":"parent_code"})
    sort: int = Field(default=0, title="排序", sa_column_kwargs={"server_default": text("0"), "comment": "排序"})
  
class Area(SQLModelBase, areaBase,table=True):
    pass
    # 定义表参数
    __table_args__ = {'comment': '地区'}
    __tablename__: str = "area" 

areaPublic = ForwardRef('areaPublic')   
class areaChildPublic(SQLModel):
    value: str
    text: str

class areaPublic(SQLModel):
    value: str
    text: str
    children: list[areaChildPublic]

class areasPublic(BaseResponse):
    data: list[areaPublic] | None  
